package cn.lichenfei.jfx.music.common.utils;

import javafx.scene.Node;
import javafx.scene.control.Tooltip;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * @author ChenFei
 * @date 2022/4/25
 */
public class JFUtils {

    public static void hideCurrentWindow(Object obj) {
        Node node = (Node) obj;
        node.getParent().getScene().getWindow().hide();
    }

    public static void setIconified(Object obj, boolean flag) {
        Node node = (Node) obj;
        Stage window = (Stage) node.getParent().getScene().getWindow();
        window.setIconified(flag);
    }

    public static <T extends Node> T getParent(Node node, Class<T> clazz) {
        return clazz.cast(node.getParent());
    }

    public static Tooltip getTooltip(String message) {
        Tooltip tooltip = new Tooltip(message);
        tooltip.setShowDelay(Duration.millis(100));
        return tooltip;
    }
}
